package com.itheima.mall.service.smsService;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.pojo.sms.SmsFlashPromotionProductRelation;
import com.itheima.pojo.sms.SmsFlashPromotionSession;
import com.itheima.mall.mapper.smsMapper.SmsFlashPromotionProductRelationMapper;
import com.itheima.mall.mapper.smsMapper.SmsFlashPromotionSessionMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsFlashPromotionSessionServiceApiImpl implements SmsFlashPromotionSessionServiceApi {
    @Autowired
    private SmsFlashPromotionSessionMapper smsFlashPromotionSessionMapper;
    @Autowired
    private SmsFlashPromotionProductRelationMapper smsFlashPromotionProductRelationMapper;

    /**
     * 添加场次
     */
    @Override
    public void create(SmsFlashPromotionSession smsFlashPromotionSession) {
        smsFlashPromotionSessionMapper.insert(smsFlashPromotionSession);
    }

    /**
     * 删除场次
     */
    @Override
    public void delete(Long id) {
       smsFlashPromotionSessionMapper.deleteById(id);
        LambdaQueryWrapper<SmsFlashPromotionProductRelation> lqw=new LambdaQueryWrapper<>();
        lqw.eq(SmsFlashPromotionProductRelation::getFlashPromotionSessionId,id);
        smsFlashPromotionProductRelationMapper.delete(lqw);
    }

    /**
     * 获取全部场次
     */
    @Override
    public List<SmsFlashPromotionSession> list() {
        return smsFlashPromotionSessionMapper.selectAll();
    }

    //根据ids查询
    @Override
    public List<SmsFlashPromotionSession> selectByIds(List<Long> flashPromotionSessionIds) {
        return smsFlashPromotionSessionMapper.selectBatchIds(flashPromotionSessionIds);
    }

    /**
     * 修改启用状态
     */
    @Override
    public void updateStatus(Long id, Long status) {
        smsFlashPromotionSessionMapper.updateStatus(id,status);
    }

    /**
     * 修改场次
     */
    @Override
    public void update(Long id, SmsFlashPromotionSession smsFlashPromotionSession) {
        smsFlashPromotionSessionMapper.updateById(smsFlashPromotionSession);
    }


    /**
     * 获取场次详情
     */
    @Override
    public SmsFlashPromotionSession getFlashSession(Long id) {
        return smsFlashPromotionSessionMapper.selectById(id);
    }
}
